package leja.notis;

import android.app.Activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.ListPreference;


public class ThemeChanger
{
    private static int sTheme;

    public final static int THEME_LIGHT = 0;
    public final static int THEME_DARK = 1;

    /**
     * Set the theme of the Activity, and restart it by creating a new Activity
     * of the same type.
     */
    public static void changeToTheme(Activity activity, int theme)
    {
        sTheme = theme;
        activity.finish();

        activity.startActivity(new Intent(activity, activity.getClass()));
    }

    /** Set the theme of the activity, according to the configuration. */
    public static void onActivityCreateSetTheme(Activity activity)
    {
        SharedPreferences prefs = activity.getPreferences(0);

        // TO DO: get the switch to use the stored theme preference

        //ListPreference lp = (ListPreference)theme;
        //sTheme = Integer.valueOf(theme.getString("pref_theme_key", ""));
        switch (sTheme)
        {
            default:
            case THEME_LIGHT:
                activity.setTheme(R.style.Theme_Light);
                break;
            case THEME_DARK:
                activity.setTheme(R.style.Theme_Dark);
                break;
        }
    }
}
